package org.freespace.controller;


import org.freespace.model.JmxScriptPlugin;
import org.freespace.service.IJmxScriptPluginService;
import org.freespace.utils.SessionUtil;
import org.freespace.utils.response.CommonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;

/**
 * <p>
 * jmx脚本绑定的插件关系表 前端控制器
 * </p>
 *
 * @author liuqi
 * @since 2023-05-25
 */
@RestController
@RequestMapping("/script-plugin")
public class JmxScriptPluginController {

    @Autowired
    IJmxScriptPluginService scriptPluginService;



    @DeleteMapping("{id}")
    public CommonResult delete(@PathVariable("id") Integer id) {
        scriptPluginService.removeById(id);
        return CommonResult.success();
    }

    @PutMapping(value = "")
    public CommonResult add(@RequestBody JmxScriptPlugin jmxScriptPlugin) {
        jmxScriptPlugin.setCreateBy(SessionUtil.getCurrentUser());
        jmxScriptPlugin.setCreateTime(LocalDateTime.now());
        scriptPluginService.save(jmxScriptPlugin);
        return CommonResult.success();
    }

//    @PostMapping(value = "list")
//    public CommonResult list(@RequestBody JmxScriptVO jmxScriptVO) {
//        Page<JmxScript> page = new Page<>(jmxScriptVO.getCurrentPage(), jmxScriptVO.getPageSize());
//        Wrapper<JmxScript> wrapper = Wrappers.query();
//        IPage<JmxScript> data = scriptService.page(page, wrapper);
//        log.info("{}", data);
//        return CommonResult.success(data);
//    }

}
